package com.webcat.controller;

import com.webcat.entity.AiResponse;
import com.webcat.entity.Response;
import com.webcat.entity.SseResponse;
import com.webcat.entity.vo.TopicVo;
import com.webcat.service.ChatService;
import com.webcat.service.QuestionService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.ai.tool.ToolCallback;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;

import java.util.List;

@RestController
@RequestMapping("/question")
@Slf4j
public class QuestionChatController {

    @Resource
    private QuestionService questionService;

    @GetMapping(value = "/start")
    public AiResponse<String> start() {
        return AiResponse.success(questionService.start());
    }

    @GetMapping(value = "/streamChat", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
    public Flux<SseResponse<Object>> streamChat(@RequestParam("chatId") String chatId, String message, String datasetId, String questionType) {
        return questionService.streamChat(chatId, message, datasetId, questionType, false);
    }

    @PostMapping(value = "/editQuestion/{chatId}")
    public SseResponse<List<TopicVo>> editQuestion(@PathVariable("chatId") String chatId, @RequestBody String message) {
        return SseResponse.success(chatId, questionService.editQuestion(chatId, message));
    }
}
